<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="org.apache.commons.fileupload.disk.*" %>
<%@ page import="org.apache.commons.fileupload.portlet.*" %>
<%@ page import="org.apache.commons.fileupload.servlet.*" %>
<%@ page import="org.apache.commons.fileupload.util.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.bafa.jdbc.*" %>
<%@ page import="java.sql.*" %>
<%

// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);


// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);

// Parse the request
List items = upload.parseRequest(request);

Iterator iter = items.iterator();
while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    
    if (!item.isFormField()) {
    if(item.getName().indexOf("csv")<1){
       out.println("ERROR, WRONG FILE TYPE");
}else{
    try{
        InputStream uploadedStream = item.getInputStream();
	BufferedInputStream bis = new BufferedInputStream(uploadedStream);
      	DataInputStream dis = new DataInputStream(bis);
      	// dis.available() returns 0 if the file does not have more lines.
	      while (dis.available() != 0) {
	
	      // this statement reads the line from the file and print it to
	        // the console.
	       out.println(dis.readLine());
	      }
	
	      // dispose all the resources after using them.
	     
	      bis.close();
      dis.close();
    	uploadedStream.close();
    } catch (IOException e) {
          e.printStackTrace();
    }
}
        /* Process a file upload in memory
	byte[] data = item.get();
	DBAccess db = new DBAccess();
	PreparedStatement updateTeam = conn.prepareStatement("insert into uploads values(?,?)");
	JAXBContext jaxbContext=JAXBContext.newInstance("com.bafa.objects.schema");
	updateTeam.setObject(2, data);		
	
	updateTeam.executeUpdate();*/
		
		
    }
}


%>